require('./index.css')
require('page/common/top-head-menu/index.js')
require('page/common/head-search/index.js')
require('page/common/footer/index.js')
require('page/common/bread-menu/index.js')
require('page/common/right-easy-menu/index.js')
require('page/common/inquery/index.js')
import validate from 'jquery-validation';
import _mm from 'util/mm.js'
import _tool from 'util/tool';
import _all from 'service/all-service';
const page ={
    pageData: {
        page:1,
        limit:12,
        seriesId: _mm.getUrlParam('tId'),
        orderParam:''
    },
    init() {
        this.bindEvent();
        this.loadList();
    },
    loadList() {
        const _this = this;
        _all.getAllProduct(_this.pageData, res=> {
            const productString = require('./productList.string');
            const _pagination = require('util/pagination/index.js');
            _this.pageData.totalCount = res.data.total;
            _pagination.init({
                pageParam: _this.pageData,
                tpl: productString,
                dataWrapper: '.product-con',
                wrapper: '.pagination-wrapper',
                obj:_this,
                callbackName:'loadList'
            });
            let html = _mm.renderHtml(productString, {data: res.data.rows});
            $('.product-content').html(html);
        }, err =>{

        });

    },
    bindEvent() {
        const _this = this;
        const pushNode = function () {
            _tool.pushNode($(this));
        };
        const addToQuote = function () {
            const name = $(this).attr('data-name');
            layer.open({
                type: 1,
                title: false,
                content: '<div class="tip-con"><div>Product has been added to cart: '+ name +'</div><div><a class="cart-link" href="/cart.html" data-type="1" data-name="Cart">show cart</a></div></div>',
                area: ['600px', '140px']
            });
        };
        const addOrder = function () {
            const $this = $(this),
            hasLight = $this.children('.arrow-up').hasClass('active'),
            typeName = $this.attr('data-typeName');
            $(this).siblings().children().removeClass('active');
            if (hasLight) {
                $this.children('.arrow-down').addClass('active').siblings().removeClass('active');
                _this.pageData.orderParam = typeName + ':1';
            } else {
                $this.children('.arrow-up').addClass('active').siblings().removeClass('active')
                _this.pageData.orderParam = typeName + ':0';
            }
            _this.loadList();
        };
        $(document).on('click', '.list-item a', pushNode);
        $(document).on('click', '.quote', addToQuote);
        $(document).on('click', '.cart-link', pushNode);
        $(document).on('click', '.order-item.can-click', addOrder);
    }
};

module.export = page.init();